//
//  MyJointribeListCell.m
//  yigou
//
//  Created by SunChao on 17/1/11.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "MyJointribeListCell.h"
#import "JoinedTribeBlock.h"
#import "TribeHeader.h"

#define imgWidth 128
#define imgHeight 85
#define imgSpace 7

@implementation MyJointribeListCell
- (void)setFrame:(CGRect)frame
{
    CGFloat kTableTopBorderWidth = 10;
    CGFloat kTableViewCellMargin = 10;
    frame.origin.y += kTableTopBorderWidth;
    frame.size.height -= kTableViewCellMargin;
    [super setFrame:frame];
}
-(void)awakeFromNib
{
    [super awakeFromNib];
    self.scrollview = [UIScrollView new];
    self.scrollview.backgroundColor = [UIColor whiteColor];
    self.scrollview.frame = CGRectMake(15, 52, ScreenWidth-30, imgHeight);
    [self.contentView addSubview:self.scrollview];
    self.scrollview.showsHorizontalScrollIndicator = NO;
}
- (IBAction)moreBtnAction:(id)sender {
     [self.delegate didClickMyJointribeWithTbibeID:@"0"];
}

-(void)contentWithArray:(NSArray *)array title:(NSString *)title
{
    self.array = [NSMutableArray new];
    self.array = array;
        self.titleLabel.text = title;
        NSUInteger numOfBlocks = array.count;
        self.scrollview.contentSize = CGSizeMake(imgWidth * numOfBlocks+7*(numOfBlocks-1)+14, 0);
    for (UIView *subView in self.scrollview.subviews) {
        [subView removeFromSuperview];
    }
        for(NSUInteger i = 0;  i< numOfBlocks; i++) {
            NSDictionary *dic = [array objectAtIndex:i];
            
            JoinedTribeBlock *block = [JoinedTribeBlock new];
            block.tag = 100+i;
            [block.img sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"tribe_logo"]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
            block.title.text = [dic objectForKey:@"tribe_name"];
            block.title.font = [UIFont systemFontOfSize:13];
            block.frame = CGRectMake((imgWidth+7)*i, 0, imgWidth, imgHeight);
            [self.scrollview addSubview:block];
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
            tapGesture.numberOfTapsRequired = 1;
            tapGesture.numberOfTouchesRequired = 1;
            [block addGestureRecognizer:tapGesture];
    }
    
}
- (void)tapGesture:(UITapGestureRecognizer *)sender{
    NSLog(@"sender:%ld",sender.view.tag);
    
   NSDictionary *dic =  [self.array objectAtIndex:sender.view.tag-100];
    NSString *tribeID = [dic objectForKey:@"tribe_id"];
    [self.delegate didClickMyJointribeWithTbibeID:tribeID];

}
@end
